<html>
<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>文章发送</title>
    <#assign base=request.contextPath  />
    <base id="basePath" href="${base}">
    <link rel="stylesheet" href="${base}/frame/layui/css/layui.css" media="all">
    <script src="${base}/frame/layui/layui.all.js" charset="utf-8"></script>
    <script type="text/javascript" src="${base}/js/zhang.js"></script>
    <script type="text/javascript" src="${base}/js/ztree/jquery-1.4.4.min.js"></script>
    <script type="text/javascript" src="${base}/js/ztree/jquery.ztree.core.js"></script>
    <script type="text/javascript" src="${base}/js/ztree/jquery.ztree.excheck.js"></script>
    <script type="text/javascript" src="${base}/js/ztree/jquery.ztree.exedit.js"></script>
    <link rel="stylesheet" href="${base}/css/demo.css" type="text/css">
    <link rel="stylesheet" href="${base}/css/zTreeStyle.css" type="text/css">
    <style type="text/css">
        .layui-btn-radius {
            border-radius: 5px;
        }
    </style>
</head>
<body>
<input type="hidden" value="${article.id}" id="id">
<form method="get" action="" id="myform" class="layui-form">
    <br>
    <div class="layui-form-item">
        <div style="height: 300px;width:450px;">
            <label class="layui-form-label">选择发送人</label>
            <ul id="tree" class="ztree"
                style="width:300px; height: 280px; overflow:auto;border:1px solid #F0F9FF;background-color: #F0F9FF;"></ul>
        </div>
        <div>
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            <input id="select_all" value="no" type="hidden">
            <a id="checkAllNodes" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-search',plain:true">全选</a>
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            <input id="no" value="no" type="hidden">
            <a id="checkAllNodesNo" href="#" >取消全选</a>
        </div>


    </div>



    <div class="layui-form-item" style="text-align:center">
        <div class="layui-inline">
            <button class="layui-btn layui-btn-radius" lay-submit lay-filter="formDemo" type="button"
                      id="onSubmit" style="background-color: #0092EF;">立即提交
            </button>
        </div>
    </div>
</form>
<script>



    layui.use(['form', 'layedit', 'laydate', 'table', 'carousel'], function () {

        var carousel = layui.carousel;
        var form = layui.form
            , $ = layui.jquery
            , layer = layui.layer
            , layedit = layui.layedit
            , laydate = layui.laydate
            , table = layui.table;
    });
    var zTreeObj,
            setting = {

                view: {
                    selectedMulti: false,
                    showLine: true,
                    dblClickExpand: false
                },

                callback: {
                    //回调函数 默认展开节点
                    onAsyncSuccess:
                            function () {
                                var treeObj = $.fn.zTree.getZTreeObj("tree");
                                treeObj.expandAll(true);
                            }

                },
                async: {
                    enable: true,
                    url: "${base}/admin/user/articleUser",
                    dataFilter:ajaxDataFilter //对Ajax返回数据进行预处理
                },
                data: {
                    simpleData: {
                        enable: true,
                        idKey: "id",
                        pIdKey: "pId",
                        rootPid: 0
                    }

                },
                check: {
                    enable: true,
                    chkStyle: "checkbox",
                    radioType: "all",
                    chkboxType: {"Y": "ps", "N": "ps"}
                },
                callback: {
                    onClick: onClick //用于捕获节点被点击的事件回调函数
                }

            };




    //初始化树
    zTreeObj = $.fn.zTree.init($("#tree"), setting);


    //点击全选  全选按钮
    var zNodes =[];
    function onClick(event, treeId, treeNode, clickFlag){

    }
    //当每次加载成功后，执行该函数
    function ajaxDataFilter(treeId, parentNode, responseData) {
        //当每次加载成功后且点击全选按钮时，将新加载后的全部节点选中，responseData表示每次新加载的所有节点
        if (responseData&&$('#select_all').val()=='yes') {
            for(var i =0; i < responseData.length; i++) {
                responseData[i].checked = true;
            }
        }
        return responseData;
    };

    function checkAllNodes() {
        $('#select_all').val('yes');
        var treeObj = $.fn.zTree.getZTreeObj("tree");
        //将现有节点全部选中（不包括还没有展开的节点）
        treeObj.checkAllNodes(true);
    };

    $(document).ready(function(){
        //初始化ztree
        $.fn.zTree.init($("#tree"), setting, zNodes);
        $("#checkAllNodes").click(checkAllNodes);
    });




//取消勾选
    function no() {
        $('#no').val('yes');
        var treeObj = $.fn.zTree.getZTreeObj("tree");
        //将现有节点全部选中（不包括还没有展开的节点）
        treeObj.checkAllNodes(false);
    };

    $(document).ready(function(){
        //初始化ztree
        $.fn.zTree.init($("#tree"), setting, zNodes);
        $("#checkAllNodesNo").click(no);
    });







</script>
<script>


    //保存
    $("#onSubmit").one("click",function(){


        if(getAllID("tree")==""){
            layer.msg("请选择用户！");
            return;
        }

        $.ajax({
            type: "POST", //提交方式
            //contentType: "application/json;charset=UTF-8",
            url: "${base}/admin/article/sendArticles",
            data: {userId : getAllID("tree")+",",articleId:$("#id").val(),title:'${article.title}',content:'${content}',createTime:'${article.createTime}'},
            success: function (data) {
                if(data.code == 1){
                    layer.msg("推送成功")
                    setTimeout(function () {
                        var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                        parent.layer.close(index); //再执行关闭
                    }, 500)
                    var table = parent.layui.table;
                    //表刷新方法
                    table.reload('testReload', {
                        url: '${base}/admin/article/selectMyPage'//数据接口
                        , where: {} //设定异步数据接口的额外参数
                    });
                }else if(data==""){
                    layer.msg("推送成功")
                    setTimeout(function () {
                        var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                        parent.layer.close(index); //再执行关闭
                    }, 500)
                    var table = parent.layui.table;
                    //表刷新方法
                    table.reload('testReload', {
                        url: '${base}/admin/article/selectMyPage'//数据接口
                        , where: {} //设定异步数据接口的额外参数
                    });
                }else {
                    layer.msg("推送失败")
                }

            }
        });
    })
</script>
</body>
</html>